package com.ceres.customer.service.impl;

import com.ceres.customer.dao.CustMenuMapper;
import com.ceres.customer.pojo.Menu;
import com.ceres.customer.service.CustMenuService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CustMenuServiceImpl implements CustMenuService {

    @Autowired
    private CustMenuMapper custMenuMapper;

    /**
     * 分页查询权限菜单方法
     *
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Page findPage(String keyword, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return (Page<Menu>) custMenuMapper.findByKeyWord(keyword);
    }

    /**
     * 查询所有权限方法
     *
     * @return
     */
    @Override
    public Map<String, List<Menu>> findAll() {
        //查询菜单信息
        List<Menu> menuList = custMenuMapper.findAllMenu();
        //查询权限信息
        List<Menu> permList = custMenuMapper.findAllPerm();
        //定义一个map
        HashMap<String, List<Menu>> map = new HashMap<>();
        //将查询出来的集合封装进map中
        map.put("menuList", menuList);
        map.put("permList", permList);
        return map;
    }

    /**
     * 根据角色查询对应权限
     * @param id
     * @return
     */
    @Override
    public Map<String, List<Menu>> findByRoleId(int id) {
        List<Menu> menuList = custMenuMapper.findMenuByRoleId(id);
        List<Menu> permList = custMenuMapper.findPermByRoleId(id);
        //定义一个map
        HashMap<String, List<Menu>> map = new HashMap<>();
        //将查询出来的集合封装进map中
        map.put("menuList", menuList);
        map.put("permList", permList);
        return map;
    }
}
